<?php 
Load::models('marca');
class MarcaController extends AppController 
{
    public function before_filter() {
        if ( !Auth::is_valid()){
            Router::redirect('usuario/login/');
        }else{
            $this->tipoMenu="marca";
        }
    }
    
    public function index()
    {
        
    }
     public function agregar()
    {
        if(Input::hasPost('marca')){
           
            $marca = new Marca(Input::post('marca'));
            
             if(!$marca->save()){
                Flash::error('Falló Operación');
                
                $this->marca = $this->post('marca');
              
            }else{
                Flash::success('Operación exitosa');
            }
        }
    }
    public function eliminar($id){
       $marca = new Marca();
       $marca = $marca->find($id);
       $marca->estado = "0";
            
       if ($marca->update()) {
            Flash::valid('Operación exitosa');
       }else{
           Flash::error('Falló Operación'); 
       }
        return Router::redirect('marca/listar');
    }
    
    public function listar(){
         $marca = new Marca();
         $this->marca =   $marca->find("order: categoria_id");
    }
    
  
    
    
    
}
?>
